package com.ruoyi.carService.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.RescueMission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.RescueMission;
import com.ruoyi.carService.service.IRescueMissionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 救援任务Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/rescue")
public class RescueMissionController extends BaseController
{
    @Autowired
    private IRescueMissionService rescueMissionService;

    /**
     * 查询救援任务列表
     */
    @RequiresPermissions("carService:rescue:list")
    @GetMapping("/list")
    public TableDataInfo list(RescueMission rescueMission)
    {
        startPage();
        List<RescueMission> list = rescueMissionService.selectRescueMissionList(rescueMission);
        return getDataTable(list);
    }

    /**
     * 导出救援任务列表
     */
    @RequiresPermissions("carService:rescue:export")
    @Log(title = "救援任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueMission rescueMission)
    {
        List<RescueMission> list = rescueMissionService.selectRescueMissionList(rescueMission);
        ExcelUtil<RescueMission> util = new ExcelUtil<RescueMission>(RescueMission.class);
        util.exportExcel(response, list, "救援任务数据");
    }

    /**
     * 获取救援任务详细信息
     */
    @RequiresPermissions("carService:rescue:query")
    @GetMapping(value = "/{orderDetailsId}")
    public AjaxResult getInfo(@PathVariable("orderDetailsId") Long orderDetailsId)
    {
        return success(rescueMissionService.selectRescueMissionByOrderDetailsId(orderDetailsId));
    }

    /**
     * 新增救援任务
     */
    @RequiresPermissions("carService:rescue:add")
    @Log(title = "救援任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RescueMission rescueMission)
    {
        return toAjax(rescueMissionService.insertRescueMission(rescueMission));
    }

    /**
     * 修改救援任务
     */
    @RequiresPermissions("carService:rescue:edit")
    @Log(title = "救援任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RescueMission rescueMission)
    {
        return toAjax(rescueMissionService.updateRescueMission(rescueMission));
    }

    /**
     * 删除救援任务
     */
    @RequiresPermissions("carService:rescue:remove")
    @Log(title = "救援任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderDetailsIds}")
    public AjaxResult remove(@PathVariable Long[] orderDetailsIds)
    {
        return toAjax(rescueMissionService.deleteRescueMissionByOrderDetailsIds(orderDetailsIds));
    }
}
